package com.example.szh.fragment.bindadapter;


import android.graphics.Color;
import android.widget.LinearLayout;

import androidx.databinding.BindingAdapter;

import com.example.szh.fragment.widget.BottomButton;
import com.example.szh.splash.data.ConfigEntity;

import java.util.List;

/**
 * @description 自定义软件框架页底部导航linearlayout
 * databinding属性
 * @author zhangxinyi
 * */
public class BottomAdapter {


    @BindingAdapter(value = {"datas","selectListener"},requireAll = true)
    public static void bottomconfig(LinearLayout linearLayout, List<ConfigEntity.DataBean> datas, BottomButton.SelectListener selectListener){
        if (datas==null)
            return;
        if (datas.size()==0)
            return;
        if (selectListener==null)
            return;
        linearLayout.removeAllViews();
        linearLayout.setOrientation(LinearLayout.HORIZONTAL);
        for (int i = 0; i < datas.size(); i++) {
            ConfigEntity.DataBean dataBean = datas.get(i);
            BottomButton bottomButton = new BottomButton(linearLayout.getContext());
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT);
            layoutParams.weight=1;
            bottomButton.setLayoutParams(layoutParams);
            bottomButton.setId(i);
            bottomButton.setSelFlag(dataBean.isSelFlag())
                    .setSelColor(Color.RED)
                    .setNomalColor(Color.BLACK)
                    .setShowPoint(false)
                    .setSelURLImg(dataBean.getSelImgURL())
                    .setNomalURLImg(dataBean.getUnSelImgURL())
                    .setListener(selectListener);
            linearLayout.addView(bottomButton);
        }
    }
}
